package com.hup.minicontroller.common.model.dto;

import com.hup.minicontroller.common.bluetooth.model.BaseBtDataPacket;
import com.hup.minicontroller.common.constant.NetConstant;
import com.hup.minicontroller.common.constant.NetConstant.DataType;
import com.hup.minicontroller.common.netty.model.BaseDataPacket;

import lombok.Data;

/**
 * 控制配置dto;
 * 服务端和客户端都会收发此数据
 */
@Data
public class ControlConfigDto implements BaseDataPacket, BaseBtDataPacket {

    /**
     * 允许控制:触摸,发送按键消息
     * 客户端不可控字段
     */
    private boolean enableControl = true;
    /**
     * 传输图像
     */
    private boolean enableScreen = true;
    /**
     * 帧率
     */
    private int fps = NetConstant.FPS[NetConstant.DEFAULT_FPS_INDEX];
    /**
     * 图像大小
     */
    private int screenSize = NetConstant.SCREEN_SIZE[NetConstant.DEFAULT_SCREEN_SIZE_INDEX];
    /**
     * 图像质量
     */
    private int screenQuality = NetConstant.SCREEN_QUALITY[NetConstant.DEFAULT_SCREEN_QUALITY_INDEX];

    @Override
    public int getType() {
        return DataType.CONTROL_CONFIG;
    }

    /**
     * 将target数据应用到本对象
     */
    public void apply(ControlConfigDto dto) {
        enableControl = dto.enableControl;
        enableScreen = dto.enableScreen;
        fps = NetConstant.getSafeFps(dto.fps);
        screenSize = NetConstant.getSafeScreenSize(dto.screenSize);
        screenQuality = NetConstant.getSafeScreenQuality(dto.screenQuality);
    }
}
